package com.carcenter.order.controller;

import com.baomidou.mybatisplus.core.conditions.Wrapper;
import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.carcenter.common.page.MyPageData;
import com.carcenter.common.result.Result;
import com.carcenter.order.entity.CarBrands;
import com.carcenter.order.service.ICarBrandsService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

import static com.baomidou.mybatisplus.core.toolkit.Wrappers.lambdaQuery;

/**
 * <p>
 *  前端控制器
 * </p>
 *
 * @author car
 * @since 2025-07-16
 */
@RestController
@RequestMapping("/car-brands")
public class CarBrandsController {
    @Autowired
    private ICarBrandsService carBrandsService;

    //详情-返回：汽车品牌表
    @GetMapping("/getDetailList/{pageNum}/{pageSize}")
    public Result<?> getDetailList(@PathVariable("pageNum") Integer pageNum,
                               @PathVariable("pageSize") Integer pageSize) {
        Page<CarBrands> page = carBrandsService.getDetailList(pageNum,pageSize);
        MyPageData data = new MyPageData(page.getTotal(),page.getRecords());
        return Result.ok(data);
    }


    //新增-品牌名
    @PostMapping("/add")
    public Result<?> add(@RequestBody CarBrands carBrands) {
        carBrandsService.add(carBrands);
        return Result.ok();
    }


    //查询-id
    @GetMapping("/getById/{id}")
    public Result<?> getById(@PathVariable Integer id) {
        CarBrands carBrands = carBrandsService.getById(id);
        return Result.ok(carBrands);
    }

    //修改-汽车品牌表
    @PutMapping("/update")
    public Result<?> update(@RequestBody CarBrands carBrands) {
        carBrandsService.updateCar(carBrands);
        return Result.ok();
    }

    //删除-id
    @DeleteMapping("/delete/{id}")
    public Result<?> delete(@PathVariable Integer id) {
        carBrandsService.removeCar(id);
        return Result.ok();
    }

}
